package com.watchthelan.web.administrator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

import com.watchthelan.domain.Administrator;
import com.watchthelan.service.administrator.AdministratorManager;

public class AdministratorAddFormController extends SimpleFormController {
	protected final Log logger = LogFactory.getLog(getClass());
	
	private AdministratorManager administratorManager;
	
	public ModelAndView onSubmit(Object command)
	throws ServletException {
		Administrator administrator = (Administrator) command;
		administratorManager.addAdministrator(administrator);
		
		logger.info("added administrator " + administrator);

		return new ModelAndView(new RedirectView(getSuccessView()));
	}

	protected Object formBackingObject(HttpServletRequest request) throws ServletException {
		Administrator administrator = new Administrator();
		return administrator;
	}	

	public AdministratorManager getAdministratorManager() {
		return administratorManager;
	}

	public void setAdministratorManager(AdministratorManager administratorManager) {
		this.administratorManager = administratorManager;
	}
	
}
